#include "Login.hpp"

int main() {
    try {
        // 创建数据库连接和UserMapper
        sql::mysql::MySQL_Driver* driver = sql::mysql::get_mysql_driver_instance();
        auto con = std::unique_ptr<sql::Connection>(driver->connect("tcp://112.74.40.147:3306", "root", "Ahqjhqj73@you"));
        con->setSchema("novel_db");
        
        UserMapper userMapper("tcp://112.74.40.147:3306", "root", "Ahqjhqj73@you", "novel_db");
        
        // 创建Login实例
        Login login(&userMapper);
        
        // 用户注册
        int userId = login.registerUser("张三", "zhangsan@example.com", "simplepassword");
        std::cout << "新用户ID: " << userId << std::endl;
        
        // 用户登录
        auto user = login.authenticate("zhangsan@example.com", "simplepassword");
        if (user) {
            std::cout << "登录成功! 欢迎, " << user->name << "!" << std::endl;
        }
        
        // 修改密码
        if (login.changePassword(userId, "simplepassword", "newpassword")) {
            std::cout << "密码修改成功!" << std::endl;
        }
        
        // 再次登录使用新密码
        user = login.authenticate("zhangsan@example.com", "newpassword");
        if (user) {
            std::cout << "使用新密码登录成功!" << std::endl;
        }
        
    } catch (const std::exception& e) {
        std::cerr << "系统错误: " << e.what() << std::endl;
        return 1;
    }
    
    return 0;
}